//-----------------Sonic CD Sound Test Script-----------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
#alias Object.Value0	:	Object.FadeValue
#alias Object.Value1	:	Object.AudioType
#alias Object.Value2	:	Object.HoldButtonTimer
#alias Object.Value3	:	Object.PCMNumber
#alias Object.Value4	:	Object.DANumber
#alias Object.Value5	:	Object.ButtonTouched
#alias Object.Value6	:	Object.PlayButtonCooldown
#alias Object.Value7	:	Object.SecretImage

// States
#alias 0	:	SOUNDTEST_SETUP
#alias 1	:	SOUNDTEST_FADE_IN
#alias 2	:	SOUNDTEST_CONTROLS
#alias 3	:	SOUNDTEST_EXIT
#alias 4	:	SOUNDTEST_SECRET_IMAGE
#alias 5	:	SOUNDTEST_SECRET_MESSAGE
#alias 6	:	SOUNDTEST_SPECIAL_STAGE

// Presentation Stages
#alias 1	:	STAGE_P_MENU

// Special Stages
#alias 7	:	STAGE_S_SS8

// Players
#alias 1	:	PLAYER_TAILS

// Global SFX
#alias 19	:	SFX_G_SPECIALWARP
#alias 27	:	SFX_G_SELECT

// Stage SFX
#alias 41	:	SFX_S_EVENT

// Engine & CallBacks
#alias 2	:	MESSAGE_LOSTFOCUS

// Device Type
#alias 1	:	RETRO_MOBILE

// Game Mode Aliases
#alias 0	:	MODE_NOSAVE

// Function Declarations
#function SoundTest_PlayTrack
#function SoundTest_CheckSecret


function SoundTest_PlayTrack
	StopMusic()
	switch Object.DANumber
	case 0
		SetMusicTrack("JP/R1A.ogg", 0, 142428)
		SetMusicTrack("US/R1A.ogg", 1, 153038)
		break

	case 1
		SetMusicTrack("R1B.ogg", 0, 354890)
		SetMusicTrack("R1B.ogg", 1, 354890)
		break

	case 2
		SetMusicTrack("JP/R1C.ogg", 0, 142902)
		SetMusicTrack("US/R1C.ogg", 1, 152346)
		break

	case 3
		SetMusicTrack("JP/R1D.ogg", 0, true)
		SetMusicTrack("US/R1D.ogg", 1, 774998)
		break

	case 4
		switch SaveRam[513]
		case 0 // Original
			SetMusicTrack("JP/R2A.ogg", 0, true)
			SetMusicTrack("JP/R2A.ogg", 1, true)
			break
		
		case 1 // US
			SetMusicTrack("US/R2A.ogg", 0, true)
			SetMusicTrack("US/R2A.ogg", 1, true)
			break
		
		case 2 // EU
			SetMusicTrack("ALT1/R2A.ogg", 0, true)
			SetMusicTrack("ALT1/R2A.ogg", 1, true)
			break
			
		case 3 // Alt. Mix 0
			SetMusicTrack("ALT2/R2A.ogg", 0, true)
			SetMusicTrack("ALT2/R2A.ogg", 1, true)
			break
		end switch
		break

	case 5
		switch SaveRam[514]
		case 0 // Original
			SetMusicTrack("R2B.ogg", 0, true)
			SetMusicTrack("R2B.ogg", 1, true)
			break
		
		case 1 // US
			SetMusicTrack("US/R2B.ogg", 0, true)
			SetMusicTrack("US/R2B.ogg", 1, true)
			break
		
		case 2 // EU
			SetMusicTrack("ALT1/R2B.ogg", 0, true)
			SetMusicTrack("ALT1/R2B.ogg", 1, true)
			break
			
		case 3 // Alt. Mix 0
			SetMusicTrack("ALT2/R2B.ogg", 0, true)
			SetMusicTrack("ALT2/R2B.ogg", 1, true)
			break
			
		case 4
			SetMusicTrack("ALT3/R2B_colterex.ogg", 0, true)
			SetMusicTrack("ALT3/R2B_colterex.ogg", 1, true)
			break
		end switch
		break

	case 6
		switch SaveRam[515]
		case 0 // JP
			SetMusicTrack("JP/R2C.ogg", 0, true)
			SetMusicTrack("JP/R2C.ogg", 1, true)
			break
			
		case 1 // US
			SetMusicTrack("US/R2C.ogg", 0, true)
			SetMusicTrack("US/R2C.ogg", 1, true)
			break
		
		case 2 // EU
			SetMusicTrack("ALT1/R2C.ogg", 0, true)
			SetMusicTrack("ALT1/R2C.ogg", 1, true)
			break
		
		case 3 // Alt. Mix 0
			SetMusicTrack("ALT2/R2C.ogg", 0, true)
			SetMusicTrack("ALT2/R2C.ogg", 1, true)
			break
			
		case 4 // Sonic Stream
			SetMusicTrack("ALT3/R2C_SonicStream.ogg", 0, true)
			SetMusicTrack("ALT3/R2C_SonicStream.ogg", 1, true)
			break
		end switch
		break

	case 7
		switch SaveRam[516]
		case 0 // JP
			SetMusicTrack("JP/R2D.ogg", 0, true)
			SetMusicTrack("JP/R2D.ogg", 1, true)
			break
		
		case 1 //US
			SetMusicTrack("US/R2D.ogg", 0, true)
			SetMusicTrack("US/R2D.ogg", 1, true)
			break
		
		case 2 // EU
			SetMusicTrack("ALT1/R2D.ogg", 0, true)
			SetMusicTrack("ALT1/R2D.ogg", 1, true)
			break
			
		case 3 // Alt. Mix0
			SetMusicTrack("ALT2/R2D.ogg", 0, true)
			SetMusicTrack("ALT2/R2D.ogg", 1, true)
			break
			
		case 4 // Alt.Mix 1
			SetMusicTrack("ALT3/R2D_colterex.ogg", 0, true)
			SetMusicTrack("ALT3/R2D_colterex.ogg", 1, true)
			break
		end switch
		break

	case 8
		SetMusicTrack("JP/R3A.ogg", 0, 358725)
		SetMusicTrack("US/R3A.ogg", 1, true)
		break

	case 9
		SetMusicTrack("R3B.ogg", 0, 166278)
		SetMusicTrack("R3B.ogg", 1, 166278)
		break

	case 10
		SetMusicTrack("JP/R3C.ogg", 0, true)
		SetMusicTrack("US/R3C.ogg", 1, 173494)
		break

	case 11
		SetMusicTrack("JP/R3D.ogg", 0, 717648)
		SetMusicTrack("US/R3D.ogg", 1, true)
		break

	case 12
		SetMusicTrack("JP/R4A.ogg", 0, true)
		SetMusicTrack("US/R4A.ogg", 1, 415148)
		break

	case 13
		SetMusicTrack("R4B.ogg", 0, true)
		SetMusicTrack("R4B.ogg", 1, true)
		break

	case 14
		SetMusicTrack("JP/R4C.ogg", 0, true)
		SetMusicTrack("US/R4C.ogg", 1, true)
		break

	case 15
		SetMusicTrack("JP/R4D.ogg", 0, true)
		SetMusicTrack("US/R4D.ogg", 1, 145616)
		break

	case 16
		switch SaveRam[543]
		case 0 // JP
			SetMusicTrack("JP/R4.5A.ogg", 0, true)
			SetMusicTrack("JP/R4.5A.ogg", 1, true)
			break
		
		case 1 // US
			SetMusicTrack("US/R4.5A.ogg", 0, true)
			SetMusicTrack("US/R4.5A.ogg", 1, true)
			break
		
		case 2 // Alt. Mix 1
			SetMusicTrack("ALT1/R4.5A.ogg", 0, true)
			SetMusicTrack("ALT1/R4.5A.ogg", 1, true)
			break
			
		case 3 // Alt. Mix 2
			SetMusicTrack("ALT2/R4.5A.ogg", 0, true)
			SetMusicTrack("ALT2/R4.5A.ogg", 1, true)
			break
		end switch
		break

	case 17
		switch SaveRam[544]
		case 0 // JP
			SetMusicTrack("R4.5B.ogg", 0, true)
			SetMusicTrack("R4.5B.ogg", 1, true)
			break
		
		case 1 // US
			SetMusicTrack("US/R4.5B.ogg", 0, true)
			SetMusicTrack("US/R4.5B.ogg", 1, true)
			break
		
		case 2 // Alt. Mix 1
			SetMusicTrack("ALT1/R4.5B.ogg", 0, true)
			SetMusicTrack("ALT1/R4.5B.ogg", 1, true)
			break
			
		case 3 // Alt. Mix 2
			SetMusicTrack("ALT2/R4.5B.ogg", 0, true)
			SetMusicTrack("ALT2/R4.5B.ogg", 1, true)
			break
		end switch
		break

	case 18
		switch SaveRam[545]
		case 0 // JP
			SetMusicTrack("JP/R4.5C.ogg", 0, true)
			SetMusicTrack("JP/R4.5C.ogg", 1, true)
			break
			
		case 1 // US
			SetMusicTrack("US/R4.5C.ogg", 0, true)
			SetMusicTrack("US/R4.5C.ogg", 1, true)
			break
		
		case 2 // Alt. Mix 1
			SetMusicTrack("ALT1/R4.5C.ogg", 0, true)
			SetMusicTrack("ALT1/R4.5C.ogg", 1, true)
			break
		
		case 3 // Alt. Mix 2
			SetMusicTrack("ALT2/R4.5C.ogg", 0, true)
			SetMusicTrack("ALT2/R4.5C.ogg", 1, true)
			break
		end switch
		break

	case 19
		switch SaveRam[546]
		case 0 // JP
			SetMusicTrack("JP/R4.5D.ogg", 0, true)
			SetMusicTrack("JP/R4.5D.ogg", 1, true)
			break
		
		case 1 //US
			SetMusicTrack("US/R4.5D.ogg", 0, true)
			SetMusicTrack("US/R4.5D.ogg", 1, true)
			break
		
		case 2 // Alt. Mix 1
			SetMusicTrack("ALT1/R4.5D.ogg", 0, true)
			SetMusicTrack("ALT1/R4.5D.ogg", 1, true)
			break
			
		case 3 // Alt. Mix 2
			SetMusicTrack("ALT2/R4.5D.ogg", 0, true)
			SetMusicTrack("ALT2/R4.5D.ogg", 1, true)
			break
		end switch
		break

	case 20
		SetMusicTrack("JP/R5A.ogg", 0, true)
		SetMusicTrack("US/R5A.ogg", 1, true)
		break

	case 21
		SetMusicTrack("R5B.ogg", 0, 619562)
		SetMusicTrack("R5B.ogg", 1, 619562)
		break

	case 22
		SetMusicTrack("JP/R5C.ogg", 0, 367046)
		SetMusicTrack("US/R5C.ogg", 1, 705830)
		break

	case 23
		SetMusicTrack("JP/R5D.ogg", 0, true)
		SetMusicTrack("US/R5D.ogg", 1, 93672)
		break

	case 24
		SetMusicTrack("JP/R6A.ogg", 0, true)
		SetMusicTrack("US/R6A.ogg", 1, 926048)
		break

	case 25
		SetMusicTrack("R6B.ogg", 0, true)
		SetMusicTrack("R6B.ogg", 1, true)
		break

	case 26
		SetMusicTrack("JP/R6C.ogg", 0, true)
		SetMusicTrack("US/R6C.ogg", 1, 181704)
		break

	case 27
		SetMusicTrack("JP/R6D.ogg", 0, true)
		SetMusicTrack("US/R6D.ogg", 1, 45355)
		break

	case 28
		SetMusicTrack("JP/R7A.ogg", 0, true)
		SetMusicTrack("US/R7A.ogg", 1, 617728)
		break

	case 29
		SetMusicTrack("R7B.ogg", 0, 730678)
		SetMusicTrack("R7B.ogg", 1, 730678)
		break

	case 30
		SetMusicTrack("JP/R7C.ogg", 0, 103060)
		SetMusicTrack("US/R7C.ogg", 1, 136670)
		break

	case 31
		SetMusicTrack("JP/R7D.ogg", 0, true)
		SetMusicTrack("US/R7D.ogg", 1, 92324)
		break

	case 32
		SetMusicTrack("JP/R8A.ogg", 0, 146030)
		SetMusicTrack("US/R8A.ogg", 1, true)
		break

	case 33
		SetMusicTrack("R8B.ogg", 0, 145748)
		SetMusicTrack("R8B.ogg", 1, 145748)
		break

	case 34
		SetMusicTrack("JP/R8C.ogg", 0, true)
		SetMusicTrack("US/R8C.ogg", 1, true)
		break
		
	case 35
		SetMusicTrack("JP/R8D.ogg", 0, true)
		SetMusicTrack("US/R8D.ogg", 1, 563962)
		break

	case 36
		SetMusicTrack("JP/Boss.ogg", 0, true)
		SetMusicTrack("US/Boss.ogg", 1, 196526)
		break

	case 37
		SetMusicTrack("JP/FinalBoss.ogg", 0, true)
		SetMusicTrack("US/FinalBoss.ogg", 1, true)
		break

	case 38
		SetMusicTrack("JP/TitleScreen.ogg", 0, false)
		SetMusicTrack("US/TitleScreen.ogg", 1, false)
		break

	case 39
		SetMusicTrack("JP/ZoneComplete.ogg", 0, false)
		SetMusicTrack("US/ZoneComplete.ogg", 1, false)
		break

	case 40
		SetMusicTrack("JP/SpeedShoes.ogg", 0, false)
		SetMusicTrack("US/SpeedShoes.ogg", 1, false)
		break

	case 41
		SetMusicTrack("JP/Invincibility.ogg", 0, false)
		SetMusicTrack("US/Invincibility.ogg", 1, false)
		break

	case 42
		SetMusicTrack("JP/GameOver.ogg", 0, false)
		SetMusicTrack("US/GameOver.ogg", 1, false)
		break

	case 43
		SetMusicTrack("JP/SpecialStage.ogg", 0, true)
		SetMusicTrack("US/SpecialStage.ogg", 1, 270972)
		break

	case 44
		SetMusicTrack("JP/DAGarden.ogg", 0, true)
		SetMusicTrack("US/DAGarden.ogg", 1, 117382)
		break

	case 45
		SetMusicTrack("JP/TimeAttack.ogg", 0, 100512)
		SetMusicTrack("US/DAGarden.ogg", 1, 117382)
		break

	end switch

	PlayMusic(Options.Soundtrack)
end function


function SoundTest_CheckSecret
	if Object.PCMNumber == 4
		if Object.DANumber == 21
			StopMusic()
			SetMusicTrack("JP/FinalBoss.ogg", 0, 1)
			SetMusicTrack("US/FinalBoss.ogg", 1, 1)
			Object.SecretImage = 0 // Batman Parody
			Object.State = SOUNDTEST_SECRET_IMAGE
		end if
	end if

	if Object.PCMNumber == 12
		if Object.DANumber == 25
			StopMusic()
			SetMusicTrack("JP/Boss.ogg", 0, 1)
			SetMusicTrack("US/Boss.ogg", 1, 196526)
			Object.SecretImage = 1 // Fun is Infinite...
			Object.State = SOUNDTEST_SECRET_IMAGE
		end if
	end if

	if Object.PCMNumber == 11
		if Object.DANumber == 9
			StopMusic()
			SetMusicTrack("JP/R1C.ogg", 0, 142902)
			SetMusicTrack("US/R1C.ogg", 1, 152346)
			Object.SecretImage = 2 // You Are Cool!
			Object.State = SOUNDTEST_SECRET_IMAGE
		end if
	end if

	if Object.PCMNumber == 3
		if Object.DANumber == 1
			StopMusic()
			SetMusicTrack("JP/R8A.ogg", 0, 146030)
			SetMusicTrack("US/R8A.ogg", 1, true)
			Object.SecretImage = 3 // Fastest DJ Alive
			Object.State = SOUNDTEST_SECRET_IMAGE
		end if
	end if

	if Object.PCMNumber == 12
		if Object.DANumber == 11
			StopMusic()
			SetMusicTrack("JP/R5C.ogg", 0, 367046)
			SetMusicTrack("US/R5C.ogg", 1, 705830)
			Stage.DebugMode = true
			Object.SecretImage = 4 // See You Next Game
			Object.State = SOUNDTEST_SECRET_IMAGE
		end if
	end if

	if Object.PCMNumber == 32
		if Object.DANumber == 8
			StopMusic()
			SetMusicTrack("JP/R5C.ogg", 0, 367046)
			SetMusicTrack("US/R5C.ogg", 1, 705830)
			Stage.PlayerListPos = PLAYER_TAILS
			Object.SecretImage = 5  // Desert Dazzle "preview"
			Object.State = SOUNDTEST_SECRET_IMAGE
		end if
	end if

	if Object.PCMNumber == 7
		if Object.DANumber == 7
			// Load the secret Robotnik Special Stage			

			StopMusic()
			PlayStageSfx(SFX_S_EVENT, false)
			Object.State = SOUNDTEST_SECRET_MESSAGE
			SetupMenu(MENU_1, 0, 3, 1)
			AddMenuEntry(MENU_1, "WELCOME TO THE SECRET SPECIAL STAGE", 1)
			CreateTempObject(TypeName[Message Text], 0, Object.XPos, Object.YPos)
			Object[TempObjectPos].iXPos = Screen.CenterX
			Object[TempObjectPos].XPos += 0x20000 // Move it 2 pixels below the Sound Test obejct
			Object[TempObjectPos].iYPos = 152
		end if
	end if
end function


sub ObjectMain
	switch Object.State
	case SOUNDTEST_SETUP
		if Object.FadeValue < 8
			Object.FadeValue++
		else
			Object.FadeValue = 254
			Object.State++
		end if
		SetScreenFade(0, 0, 0, 255)
		break

	case SOUNDTEST_FADE_IN
		if Object.FadeValue > 0
			SetScreenFade(0, 0, 0, Object.FadeValue)
			Object.FadeValue -= 8
		else
			Object.State++
		end if
		break

	case SOUNDTEST_CONTROLS
		if Object.PlayButtonCooldown > 0
			Object.PlayButtonCooldown--
		end if

		if Object.AudioType == 0
			if KeyPress[0].Up == true
				Object.HoldButtonTimer = 0
				Object.PCMNumber--
				if Object.PCMNumber < 0
					Object.PCMNumber = 69
				end if
			else
				if KeyPress[0].Down == true
					Object.HoldButtonTimer = 0
					Object.PCMNumber++
					if Object.PCMNumber > 69
						Object.PCMNumber = 0
					end if
				end if
			end if

			if KeyDown[0].Up == true
				Object.HoldButtonTimer++
				if Object.HoldButtonTimer == 8
					Object.HoldButtonTimer = 0
					Object.PCMNumber--
					if Object.PCMNumber < 0
						Object.PCMNumber = 69
					end if
				end if
			else
				if KeyDown[0].Down == true
					Object.HoldButtonTimer++
					if Object.HoldButtonTimer == 8
						Object.HoldButtonTimer = 0
						Object.PCMNumber++
						if Object.PCMNumber > 69
							Object.PCMNumber = 0
						end if
					end if
				end if
			end if

			if KeyPress[0].Left == true
				Object.AudioType = 1
			end if

			if KeyPress[0].Right == true
				Object.AudioType = 1
			end if

#platform: Use_Standalone
			TempValue0  = KeyPress[0].ButtonA
			TempValue0 |= KeyPress[0].ButtonB
			TempValue0 |= KeyPress[0].ButtonC
#endplatform

#platform: Use_Origins
			TempValue0  = KeyPress[0].ButtonA
			TempValue0 |= KeyPress[0].Start
			TempValue0 |= KeyPress[0].ButtonC
#endplatform

			if TempValue0 == true
				CallFunction(SoundTest_CheckSecret)
				if Object.State == SOUNDTEST_CONTROLS
					TempValue2 = Object.PCMNumber
					if TempValue2 >= 28
						TempValue2 += 1
					end if
					PlaySfx(TempValue2, false)
					StopMusic()
				end if
			end if
		else
			if KeyPress[0].Up == true
				Object.HoldButtonTimer = 0
				Object.DANumber--
				if Object.DANumber < 0
					Object.DANumber = 45
				end if
			else
				if KeyPress[0].Down == true
					Object.HoldButtonTimer = 0
					Object.DANumber++
					if Object.DANumber > 45
						Object.DANumber = 0
					end if
				end if
			end if

			if KeyDown[0].Up == true
				Object.HoldButtonTimer++
				if Object.HoldButtonTimer == 8
					Object.HoldButtonTimer = 0
					Object.DANumber--
					if Object.DANumber < 0
						Object.DANumber = 45
					end if
				end if
			else
				if KeyDown[0].Down == true
					Object.HoldButtonTimer++
					if Object.HoldButtonTimer == 8
						Object.HoldButtonTimer = 0
						Object.DANumber++
						if Object.DANumber > 45
							Object.DANumber = 0
						end if
					end if
				end if
			end if

			if KeyPress[0].Left == true
				Object.AudioType = 0
			end if

			if KeyPress[0].Right == true
				Object.AudioType = 0
			end if

#platform: Use_Standalone
			TempValue0  = KeyPress[0].ButtonA
			TempValue0 |= KeyPress[0].ButtonB
			TempValue0 |= KeyPress[0].ButtonC
#endplatform

#platform: Use_Origins
			TempValue0  = KeyPress[0].ButtonA
			TempValue0 |= KeyPress[0].Start
			TempValue0 |= KeyPress[0].ButtonC
#endplatform

			if TempValue0 == true
				if Object.PlayButtonCoolDown == false
					CallFunction(SoundTest_CheckSecret)
					if Object.State == SOUNDTEST_CONTROLS
						CallFunction(SoundTest_PlayTrack)
						Object.PlayButtonCooldown = 60
					end if
				end if
			end if
		end if

#platform: Use_Standalone
		if KeyPress[0].Start == true
			CallFunction(SoundTest_CheckSecret)
			if Object.State == SOUNDTEST_CONTROLS
				StopMusic()
				Object.State++
			end if
		end if
#endplatform

#platform: Use_Origins
		if KeyPress[0].ButtonB == true
			CallFunction(SoundTest_CheckSecret)
			if Object.State == SOUNDTEST_CONTROLS
				StopMusic()
				Object.State++
			end if
		end if

		if Engine.DeviceType == RETRO_MOBILE
			TempValue0 = Screen.CenterX
			TempValue0 -= 126
			TempValue1 = Screen.CenterX
			TempValue1 -= 66
			CheckTouchRect(TempValue0, 20, TempValue1, 72)
			if CheckResult > -1
				Object.AudioType = 0
				KeyDown[0].Up = true
				Object.HoldButtonTimer++
				if Object.HoldButtonTimer == 8
					Object.HoldButtonTimer = 0
					Object.PCMNumber--
					if Object.PCMNumber < 0
						Object.PCMNumber = 69
					end if
				end if
			end if
			
			CheckTouchRect(TempValue0, 134, TempValue1, 186)
			if CheckResult > -1
				Object.AudioType = 0
				KeyDown[0].Down = true
				Object.HoldButtonTimer++
				if Object.HoldButtonTimer == 8
					Object.HoldButtonTimer = 0
					Object.PCMNumber++
					if Object.PCMNumber > 69
						Object.PCMNumber = 0
					end if
				end if
			end if
			
			TempValue0 = Screen.CenterX
			TempValue0 += 66
			TempValue1 = Screen.CenterX
			TempValue1 += 126
			CheckTouchRect(TempValue0, 20, TempValue1, 72)
			if CheckResult > -1
				Object.AudioType = 1
				KeyDown[0].Up = true
				Object.HoldButtonTimer++
				if Object.HoldButtonTimer == 8
					Object.HoldButtonTimer = 0
					Object.DANumber--
					if Object.DANumber < 0
						Object.DANumber = 45
					end if
				end if
			end if
			
			CheckTouchRect(TempValue0, 134, TempValue1, 186)
			if CheckResult > -1
				Object.AudioType = 1
				KeyDown[0].Down = true
				Object.HoldButtonTimer++
				if Object.HoldButtonTimer == 8
					Object.HoldButtonTimer = 0
					Object.DANumber++
					if Object.DANumber > 45
						Object.DANumber = 0
					end if
				end if
			end if

			if Engine.Message == MESSAGE_LOSTFOCUS
				Object.ButtonTouched = false
			end if

			TempValue0 = Screen.CenterX
			TempValue0 -= 22
			TempValue1 = Screen.CenterX
			TempValue1 += 22
			CheckTouchRect(TempValue0, 116, TempValue1, 140)
			if CheckResult > -1
				Object.ButtonTouched = true
			else
				CheckTouchRect(0, 0, Screen.XSize, Screen.YSize)
				if CheckResult < 0
					if Object.ButtonTouched == true
						Object.ButtonTouched = false
						CallFunction(SoundTest_CheckSecret)
						if Object.State == SOUNDTEST_CONTROLS
							if Object.AudioType == 0
								TempValue2 = Object.PCMNumber
								if TempValue2 >= 28
									TempValue2 += 1
								end if
								PlaySfx(TempValue2, false)
							else
								if Object.PlayButtonCoolDown == 0
									CallFunction(SoundTest_PlayTrack)
									Object.PlayButtonCoolDown = 60
								end if
							end if
						end if
					end if
				else
					if Object.ButtonTouched == true
						Object.ButtonTouched = false
					end if
				end if
			end if
			
			CheckTouchRect(TempValue0, 148, TempValue1, 172)
			if CheckResult > -1
				Object.ButtonTouched = 2
			else
				CheckTouchRect(0, 0, Screen.XSize, Screen.YSize)
				if CheckResult < 0
					if Object.ButtonTouched == 2
						Object.ButtonTouched = 0
						StopMusic()
					end if
				else
					if Object.ButtonTouched == 2
						Object.ButtonTouched = 0
					end if
				end if
			end if
			
			CheckTouchRect(TempValue0, 180, TempValue1, 204)
			if CheckResult > -1
				Object.ButtonTouched = 3
			else
				CheckTouchRect(0, 0, Screen.XSize, Screen.YSize)
				if CheckResult < 0
					if Object.ButtonTouched == 3
						Object.ButtonTouched = 0
						PlaySfx(SFX_G_SELECT, false) 
						Object.State++
						StopMusic()
					end if
				else
					if Object.ButtonTouched == 3
						Object.ButtonTouched = 0
					end if
				end if
			end if
		end if
#endplatform

#platform: Mobile
		TempValue0 = Screen.CenterX
		TempValue0 -= 126
		TempValue1 = Screen.CenterX
		TempValue1 -= 66
		CheckTouchRect(TempValue0, 20, TempValue1, 72)
		if CheckResult > -1
			Object.AudioType = 0
			KeyDown[0].Up = true
			Object.HoldButtonTimer++
			if Object.HoldButtonTimer == 8
				Object.HoldButtonTimer = 0
				Object.PCMNumber--
				if Object.PCMNumber < 0
					Object.PCMNumber = 69
				end if
			end if
		end if

		CheckTouchRect(TempValue0, 134, TempValue1, 186)
		if CheckResult > -1
			Object.AudioType = 0
			KeyDown[0].Down = true
			Object.HoldButtonTimer++
			if Object.HoldButtonTimer == 8
				Object.HoldButtonTimer = 0
				Object.PCMNumber++
				if Object.PCMNumber > 69
					Object.PCMNumber = 0
				end if
			end if
		end if

		TempValue0 = Screen.CenterX
		TempValue0 += 66
		TempValue1 = Screen.CenterX
		TempValue1 += 126
		CheckTouchRect(TempValue0, 20, TempValue1, 72)
		if CheckResult > -1
			Object.AudioType = 1
			KeyDown[0].Up = true
			Object.HoldButtonTimer++
			if Object.HoldButtonTimer == 8
				Object.HoldButtonTimer = 0
				Object.DANumber--
				if Object.DANumber < 0
					Object.DANumber = 45
				end if
			end if
		end if

		CheckTouchRect(TempValue0, 134, TempValue1, 186)
		if CheckResult > -1
			Object.AudioType = 1
			KeyDown[0].Down = true
			Object.HoldButtonTimer++
			if Object.HoldButtonTimer == 8
				Object.HoldButtonTimer = 0
				Object.DANumber++
				if Object.DANumber > 45
					Object.DANumber = 0
				end if
			end if
		end if

		if Engine.Message == MESSAGE_LOSTFOCUS
			Object.ButtonTouched = 0
		end if

		TempValue0 = Screen.CenterX
		TempValue0 -= 22
		TempValue1 = Screen.CenterX
		TempValue1 += 22
		CheckTouchRect(TempValue0, 116, TempValue1, 140)
		if CheckResult > -1
			Object.ButtonTouched = 1
		else
			CheckTouchRect(0, 0, Screen.XSize, Screen.YSize)
			if CheckResult < 0
				if Object.ButtonTouched == true
					Object.ButtonTouched = false
					CallFunction(SoundTest_CheckSecret)
					if Object.State == SOUNDTEST_CONTROLS
						if Object.AudioType == 0
							PlaySfx(Object.PCMNumber, false)
						else
							if Object.PlayButtonCoolDown == false
								CallFunction(SoundTest_PlayTrack)
								Object.PlayButtonCooldown = 60
							end if
						end if
					end if
				end if
			else
				if Object.ButtonTouched == 1
					Object.ButtonTouched = false
				end if
			end if
		end if

		CheckTouchRect(TempValue0, 148, TempValue1, 172)
		if CheckResult > -1
			Object.ButtonTouched = 2
		else
			CheckTouchRect(0, 0, Screen.XSize, Screen.YSize)
			if CheckResult < 0
				if Object.ButtonTouched == 2
					Object.ButtonTouched = 0
					StopMusic()
				end if
			else
				if Object.ButtonTouched == 2
					Object.ButtonTouched = 0
				end if
			end if
		end if

		CheckTouchRect(TempValue0, 180, TempValue1, 204)
		if CheckResult > -1
			Object.ButtonTouched = 3
		else
			CheckTouchRect(0, 0, Screen.XSize, Screen.YSize)
			if CheckResult < 0
				if Object.ButtonTouched == 3
					Object.ButtonTouched = 0
					PlaySfx(SFX_G_SELECT, false) 
					Object.State++
					StopMusic()
				end if
			else
				if Object.ButtonTouched == 3
					Object.ButtonTouched = 0
				end if
			end if
		end if
#endplatform
		break

	case SOUNDTEST_EXIT
		if Object.FadeValue < 288
			Object.FadeValue += 8
		else
			Options.GameMode = MODE_NOSAVE
			Stage.ListPos	 = STAGE_P_MENU
			LoadStage()
		end if
		
		TempValue0 = Object.FadeValue
		if TempValue0 > 255
			TempValue0 = 255
		end if
		SetScreenFade(0, 0, 0, TempValue0)
		break

	case SOUNDTEST_SECRET_IMAGE
		if Object.FadeValue < 288
			Object.FadeValue += 16
		else
			Object.Type = TypeName[Blank Object]
			if Object.SecretImage > 4
				CreateTempObject(TypeName[Secret Image 2], 0, Object.XPos, Object.YPos)
			else
				CreateTempObject(TypeName[Secret Image], Object.SecretImage, Object.XPos, Object.YPos)
			end if
		end if
		SetScreenFade(0, 0, 0, Object.FadeValue)
		break

	case SOUNDTEST_SECRET_MESSAGE
		if Object.FadeValue < 120
			Object.FadeValue++
		else
			Object.FadeValue = 0
			Object.State++
			PlaySfx(SFX_G_SPECIALWARP, false) 
		end if
		break

	case SOUNDTEST_SPECIAL_STAGE
		if Object.FadeValue < 1024
			Object.FadeValue += 8
		else
			Object.Type = TypeName[Blank Object]
			Fade_Colour = 208
			Fade_Colour <<= 16
			TempValue0 = 255
			TempValue0 <<= 8
			Fade_Colour += TempValue0
			Fade_Colour += 224
			Options.GameMode = MODE_NOSAVE
			Stage.ActiveList = SPECIAL_STAGE

#platform: Use_Origins
			Stage.ActiveList = 3
#endplatform
			Stage.ListPos = STAGE_S_SS8
			LoadStage()
		end if
		SetScreenFade(208, 255, 224, Object.FadeValue)
		break

	end switch
end sub


sub ObjectDraw
	TempValue0 = 0
	while TempValue0 < 240
		TempValue1 = 0
		while TempValue1 < Screen.XSize
			DrawSpriteScreenXY(15, TempValue1, TempValue0)
			TempValue1 += 224
		loop
		TempValue0 += 48
	loop
	DrawSpriteScreenXY(16, Screen.CenterX, 64)

	TempValue0 = Screen.CenterX
	TempValue0 -= 118
	if Object.AudioType == 0
		DrawSpriteScreenXY(11, TempValue0, 96)
	else
		DrawSpriteScreenXY(10, TempValue0, 96)
	end if

	TempValue0 += 56
	TempValue1 = Object.PCMNumber
	TempValue1 /= 10
	DrawSpriteScreenXY(TempValue1, TempValue0, 96)

	TempValue0 += 8
	TempValue1 = Object.PCMNumber
	TempValue1 %= 10
	DrawSpriteScreenXY(TempValue1, TempValue0, 96)

	TempValue0 += 102
	if Object.AudioType == 1
		DrawSpriteScreenXY(13, TempValue0, 96)
	else
		DrawSpriteScreenXY(12, TempValue0, 96)
	end if

	TempValue0 += 48
	TempValue1 = Object.DANumber
	TempValue1 /= 10
	DrawSpriteScreenXY(TempValue1, TempValue0, 96)

	TempValue0 += 8
	TempValue1 = Object.DANumber
	TempValue1 %= 10
	DrawSpriteScreenXY(TempValue1, TempValue0, 96)
#platform: Use_Origins
	if Engine.DeviceType == RETRO_MOBILE
		if Object.State < 5
			TempValue0 = Screen.CenterX
			TempValue0 -= 96

			if Object.AudioType == 0
				if KeyDown[0].Up == true
					DrawSpriteScreenXY(18, TempValue0, 48)
				else
					DrawSpriteScreenXY(17, TempValue0, 48)
				end if
				if KeyDown[0].Down == true
					DrawSpriteScreenXY(20, TempValue0, 160)
				else
					DrawSpriteScreenXY(19, TempValue0, 160)
				end if
			else
				DrawSpriteScreenXY(17, TempValue0, 48)
				DrawSpriteScreenXY(19, TempValue0, 160)
			end if

			TempValue0 += 192
			if Object.AudioType == 1
				if KeyDown[0].Up == true
					DrawSpriteScreenXY(18, TempValue0, 48)
				else
					DrawSpriteScreenXY(17, TempValue0, 48)
				end if
				if KeyDown[0].Down == true
					DrawSpriteScreenXY(20, TempValue0, 160)
				else
					DrawSpriteScreenXY(19, TempValue0, 160)
				end if
			else
				DrawSpriteScreenXY(17, TempValue0, 48)
				DrawSpriteScreenXY(19, TempValue0, 160)
			end if

			TempValue0 = 128
			if Object.ButtonTouched == 1
				DrawSpriteScreenXY(22, Screen.CenterX, TempValue0)
			else
				DrawSpriteScreenXY(21, Screen.CenterX, TempValue0)
			end if

			TempValue0 += 32
			if Object.ButtonTouched == 2
				DrawSpriteScreenXY(24, Screen.CenterX, TempValue0)
			else
				DrawSpriteScreenXY(23, Screen.CenterX, TempValue0)
			end if

			TempValue0 += 32
			if Object.ButtonTouched == 3
				DrawSpriteScreenXY(26, Screen.CenterX, TempValue0)
			else
				DrawSpriteScreenXY(25, Screen.CenterX, TempValue0)
			end if
		end if
	end if
#endplatform

#platform: Use_Standalone
	#platform: Mobile
		if Object.State < 5
			TempValue0 = Screen.CenterX
			TempValue0 -= 96

			if Object.AudioType == 0
				if KeyDown[0].Up == true
					DrawSpriteScreenXY(18, TempValue0, 48)
				else
					DrawSpriteScreenXY(17, TempValue0, 48)
				end if
				if KeyDown[0].Down == true
					DrawSpriteScreenXY(20, TempValue0, 160)
				else
					DrawSpriteScreenXY(19, TempValue0, 160)
				end if
			else
				DrawSpriteScreenXY(17, TempValue0, 48)
				DrawSpriteScreenXY(19, TempValue0, 160)
			end if

			TempValue0 += 192
			if Object.AudioType == 1
				if KeyDown[0].Up == true
					DrawSpriteScreenXY(18, TempValue0, 48)
				else
					DrawSpriteScreenXY(17, TempValue0, 48)
				end if
				if KeyDown[0].Down == true
					DrawSpriteScreenXY(20, TempValue0, 160)
				else
					DrawSpriteScreenXY(19, TempValue0, 160)
				end if
			else
				DrawSpriteScreenXY(17, TempValue0, 48)
				DrawSpriteScreenXY(19, TempValue0, 160)
			end if

			TempValue0 = 128
			if Object.ButtonTouched == 1
				DrawSpriteScreenXY(22, Screen.CenterX, TempValue0)
			else
				DrawSpriteScreenXY(21, Screen.CenterX, TempValue0)
			end if

			TempValue0 += 32
			if Object.ButtonTouched == 2
				DrawSpriteScreenXY(24, Screen.CenterX, TempValue0)
			else
				DrawSpriteScreenXY(23, Screen.CenterX, TempValue0)
			end if

			TempValue0 += 32
			if Object.ButtonTouched == 3
				DrawSpriteScreenXY(26, Screen.CenterX, TempValue0)
			else
				DrawSpriteScreenXY(25, Screen.CenterX, TempValue0)
			end if
		end if
	#endplatform
#endplatform
end sub


sub ObjectStartup
	LoadSpriteSheet("Secrets/SecretMenus.gif")
	SpriteFrame(0, 0, 8, 16, 1, 49)				// #0  - 0
	SpriteFrame(0, 0, 8, 16, 10, 49)			// #1  - 1
	SpriteFrame(0, 0, 8, 16, 19, 49)			// #2  - 2
	SpriteFrame(0, 0, 8, 16, 28, 49)			// #3  - 3
	SpriteFrame(0, 0, 8, 16, 1, 66)				// #4  - 4
	SpriteFrame(0, 0, 8, 16, 10, 66)			// #5  - 5
	SpriteFrame(0, 0, 8, 16, 19, 66)			// #6  - 6
	SpriteFrame(0, 0, 8, 16, 28, 66)			// #7  - 7
	SpriteFrame(0, 0, 8, 16, 1, 83)				// #8  - 8
	SpriteFrame(0, 0, 8, 16, 10, 83)			// #9  - 9
	SpriteFrame(0, 0, 56, 16, 136, 83)			// #10 - PCM NO.
	SpriteFrame(0, 0, 56, 16, 136, 100)			// #11 - PCM NO. Highlight
	SpriteFrame(0, 0, 48, 16, 193, 83)			// #12 - DA NO.
	SpriteFrame(0, 0, 48, 16, 193, 100)			// #13 - DA NO. Highlight
	SpriteFrame(0, 0, 8, 16, 19, 83)			// #14 - "-"
	SpriteFrame(0, 0, 224, 48, 0, 0)			// #15 - Background
	SpriteFrame(-40, 0, 96, 16, 136, 49)		// #16 - Sound Test
	SpriteFrame(-10, -10, 20, 20, 136, 117)		// #17 - Up Arrow
	SpriteFrame(-10, -10, 20, 20, 136, 138)		// #18 - Up Arrow Highlight
	SpriteFrame(-10, -10, 20, 20, 157, 117)		// #19 - Down Arrow
	SpriteFrame(-10, -10, 20, 20, 157, 138)		// #20 - Down Arrow Highlight
	SpriteFrame(-20, -10, 40, 20, 200, 201)		// #21 - Play Button
	SpriteFrame(-20, -10, 40, 20, 200, 222)		// #22 - Play Button Highlight
	SpriteFrame(-20, -10, 40, 20, 159, 201)		// #23 - Stop Button
	SpriteFrame(-20, -10, 40, 20, 159, 222)		// #24 - Stop Button Highlight
	SpriteFrame(-20, -10, 40, 20, 200, 159)		// #25 - Exit Button
	SpriteFrame(-20, -10, 40, 20, 200, 180)		// #26 - Exit Button Highlight
end sub


// ========================
// Editor Subs
// ========================

sub RSDKDraw
	DrawSprite(0)
end sub


sub RSDKLoad
	LoadSpriteSheet("Secrets/SecretMenus.gif")
	SpriteFrame(-40, 0, 96, 16, 136, 49)		// #0 - Sound Test

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end sub
